/**
 * Created by dev-001 on 2017/2/28.
 * 班级
 */
import mongoose from 'mongoose';
const Schema = mongoose.Schema;
const ObjectId = Schema.Types.ObjectId;

const ClazzSchema = new Schema({
    name: String,//班级名称，初一二班
    school: {
        type: ObjectId,
        ref: 'School'
    },//学校字段做冗余，方便查询
    virtual: Boolean,//是否为虚拟班级
    type: Number,//1理科，2文科，3艺体
    upgrade: {
        type: ObjectId,
        ref: 'Clazz'
    },//升级方向
    subClazz: {
        type: ObjectId,
        ref: 'Clazz'
    },//当前绑定的虚拟绑架
    parentClazz: {
        type: ObjectId,
        ref: 'Clazz'
    },//绑定的实体班级，虚拟班级失效后，该字段不删除
    grade: {
        type: ObjectId,
        ref: 'Grade'
    },
    status: Boolean,
    createdAt: Date,
    updatedAt: Date
});

ClazzSchema.pre('save', function (next) {
    this.createdAt = new Date();
    next();
});

export default mongoose.model('Clazz', ClazzSchema);